package com.hd.auto;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;

import net.sf.json.JSONObject;

import org.apache.commons.logging.Log;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.testng.TestNG;
import org.testng.xml.Parser;
import org.testng.xml.XmlSuite;
import org.xml.sax.SAXException;






public class Test {

	
	/**
	 * @param args
	 * @throws ParseException 
	 */
	public static void main(String[] args) {
//		ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
//		TestSpring test = (TestSpring)context.getBean("testSrping");
//		test.printHello();

//		String bb = "{\"Transaction\":{\"TransHeader\":{\"res_code\":\"0000\",\"err_mes\":\"交易成功！\",\"tran_date\":\"2018/01/18\",\"tran_time\":\"14:35:49\"},\"TransBody\":{\"applyno\":\"2018011800000002\",\"appserialno\":\"18011814354157600045\",\"applyresult\":\"10\"}}}";
//		JSONObject json = JSONObject.fromObject(bb);  
//		System.err.println(json.getJSONObject("Transaction").getJSONObject("TransHeader").getString("res_code"));
//		System.err.println(json.getJSONObject("Transaction").getJSONObject("TransBody").getString("applyno"));
//		System.err.println(json.getJSONObject("Transaction").getJSONObject("TransBody").getString("appserialno"));
//		System.out.println(args[0]);
		
		TestNG tng = new TestNG();
	
//		tng.setTestClasses(new Class[]{com.hd.auto.CopyOfLoanReqToOFCTest.class});
//		tng.run();
//		
		Parser parser = null;
		
		if("JSD".equals(args[0])){
			parser = new Parser("./testng-jsd.xml");
		}else if("MD".equals(args[0])){
			parser = new Parser("./testng-md.xml");
		}else if("YZD".equals(args[0])){
			parser = new Parser("./testng.xml");
		}else{
			//也可以接受用户直接输入需要加载的xml，此处为绝对路径
			parser = new Parser(args[0]);
		}
//手动输入需要执行的xml时，已输入的为准	
//		if(args.length>1){
//			if(!"".equals(args[1])&&args[1]!=null){
//				parser = new Parser(args[1]);
//			}
//			
//		}
		
		List<XmlSuite> suites = new ArrayList<XmlSuite>();
		try {
		suites = parser.parseToList();
		} catch (ParserConfigurationException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		} catch (SAXException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		};
		tng.setXmlSuites(suites);
		tng.run();
	}

}
